package com.xbao.controller;

import com.xbao.service.RoomService;
import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.req.RoomReq;
import com.xbao.model.vo.RoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/9/5.
 */
@Api(value = "/room", tags = "room")
@RequestMapping(value = "room")
@Controller
@EnableAutoConfiguration
public class RoomController extends BaseController {
    @Resource
    private RoomService roomSerivce;

    /**
     * @param roomReqCommRequest
     * @return
     */
    @ApiOperation(value = "addRoom", notes = "addRoom")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public CommResult addRoom(@RequestBody CommRequest<RoomReq> roomReqCommRequest) {
        //TODO 字段不全
        roomSerivce.addRoom(roomReqCommRequest.getData());
        return result();
    }

    /**
     * @param roomReqCommRequest
     * @return
     */
    @ApiOperation(value = "modifyRoom", notes = "modifyRoom")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public CommResult modifyRoom(@RequestBody CommRequest<RoomReq> roomReqCommRequest) {
        roomSerivce.modifyRoom(roomReqCommRequest.getData());
        return result();
    }

    /**
     * @param roomReqCommRequest
     * @return
     */
    @ApiOperation(value = "detailRoom", notes = "detailRoom")
    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    @ResponseBody
    public CommResult detailRoom( @RequestBody CommRequest<RoomReq> roomReqCommRequest) {
        RoomVo roomVo = roomSerivce.detailRoom(roomReqCommRequest.getData().getId());
        return new CommResult<RoomVo>(roomVo);
    }

    /**
     * @param roomReqCommRequest
     * @return
     */
    @ApiOperation(value = "deleteRoom", notes = "deleteRoom")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public CommResult deleteRoom( @RequestBody CommRequest<RoomReq> roomReqCommRequest) {
        roomSerivce.deleteRoom(roomReqCommRequest.getData().getId());
        return result();
    }



    /**
     * @param roomReqCommRequest
     */
    @ApiOperation(value = "listRooms", notes = "listRooms")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<RoomVo>> listRooms( @RequestBody CommRequest<RoomReq> roomReqCommRequest) {
        List<RoomVo> v = roomSerivce.queryRooms(roomReqCommRequest.getData());
        return new CommResult<List<RoomVo>>(v);
    }


}
